﻿using UnityEngine;
using System.Collections;

public class CameraShake : MonoBehaviour
{
    private float shake = 35;

    private float setShake;

    private bool shakeSwitch = false;

    public static CameraShake instance;

    public void Awake()
    {
        instance = this;
        setShake = shake;
    }

    public void ShakeCa()
    {
        shake = setShake;

        shakeSwitch = true;
    }

    void Update()
    {

        if (shakeSwitch == true)
        {

            gameObject.transform.localPosition = new Vector3(Random.Range(0f, shake * 2f) - shake, transform.localPosition.y+60, transform.localPosition.z);

            gameObject.transform.localPosition = new Vector3(transform.localPosition.x, Random.Range(0f, shake * 1f) - shake+60, transform.localPosition.z);

            shake = shake / 1.05f;

            if (shake < 0.05)
            {

                shake = 0;

                shakeSwitch = false;

            }

        }

    }

}
